home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / gplot3_2.lha / gnuplot / term / dumb.trm < prev    next >
Text File  |  1992-03-25  |  6KB  |  307 lines

  1. /*
  2.  * $Id: dumb.trm,v 3.26 92/03/24 22:34:48 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - dumb.trm */
  6. /*
  7.  * Copyright (C) 1991, 1992
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted,
  11.  * provided that the above copyright notice appear in all copies and
  12.  * that both that copyright notice and this permission notice appear
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed
  17.  * as patches to released version.
  18.  *
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  *
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   DUMB terminals
  25.  *
  26.  * AUTHORS
  27.  *   Francois Pinard, 91-04-03
  28.  *           INTERNET: pinard@iro.umontreal.ca
  29.  *
  30.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  31.  *
  32.  */
  33.  
  34. #define DUMB_AXIS_CONST '\1'
  35. #define DUMB_BORDER_CONST '\2'
  36.  
  37. #define DUMB_XMAX 79
  38. #define DUMB_YMAX 24
  39.  
  40. static char *dumb_matrix = NULL;      /* matrix of characters */
  41. static char *dumb_priority = NULL;    /* matrix of priority at each position */
  42. static char dumb_pen;                 /* current character used to draw */
  43. static int dumb_x;                    /* current X position */
  44. static int dumb_y;                    /* current Y position */
  45. static int dumb_xmax = DUMB_XMAX;
  46. static int dumb_ymax = DUMB_YMAX;
  47.  
  48. #define DUMB_PIXEL(x,y) dumb_matrix[dumb_xmax*(y)+(x)]
  49.  
  50.  
  51. dumb_set_pixel(x,y,v,p)
  52. int x,y,v,p;
  53. {
  54.   if (p > dumb_priority[dumb_xmax*y+x])
  55.     {
  56.       dumb_matrix[dumb_xmax*y+x] = v;
  57.       dumb_priority[dumb_xmax*y+x] = p;
  58.     }
  59. }
  60.  
  61.  
  62. DUMB_options()
  63. {
  64.   int x,y;
  65.   struct value a;
  66.   extern struct value *const_express();
  67.   extern double real();
  68.  
  69.   if (!END_OF_COMMAND) {
  70.     x = (int) real(const_express(&a));
  71.     if (!END_OF_COMMAND) {
  72.       y = (int) real(const_express(&a));
  73.       dumb_xmax = term_tbl[term].xmax = x;
  74.       dumb_ymax = term_tbl[term].ymax = y;
  75.     }
  76.   }
  77.  
  78.   sprintf(term_options, "%d %d",dumb_xmax,dumb_ymax);
  79. }
  80.  
  81.  
  82. DUMB_init()
  83. {
  84.   if (dumb_matrix)
  85.     free(dumb_matrix);
  86.  
  87.   dumb_matrix = alloc (dumb_xmax * dumb_ymax * 2, "dumb terminal");
  88.  
  89.   dumb_priority = dumb_matrix + dumb_xmax * dumb_ymax;
  90. }
  91.  
  92.  
  93. char *
  94. DUMB_str_state()
  95. {
  96.    static char str[80];
  97.  
  98.    sprintf( str, "%d %d", dumb_xmax, dumb_ymax );
  99.  
  100.    return str;
  101. }
  102.  
  103.  
  104. DUMB_graphics ()
  105. {
  106.   int i;
  107.   char *pm = dumb_matrix, *pp = dumb_priority;
  108.  
  109.   for ( i = dumb_xmax * dumb_ymax; i > 0; i-- ) {
  110.     *pm++ = ' ';
  111.     *pp++ = 0;
  112.   }
  113. }
  114.  
  115.  
  116. DUMB_text ()
  117. {
  118.   int x, y, l;
  119.  
  120.   putc ('\f', outfile);
  121.   for (y = dumb_ymax - 1; y >= 0; y--)
  122.     {
  123.       for (l = dumb_xmax; l > 0 && DUMB_PIXEL (l - 1, y) == ' '; l--)
  124.        ;
  125.       for (x = 0; x < l; x++)
  126.        putc (DUMB_PIXEL (x, y), outfile);
  127.       if (y > 0)
  128.        putc ('\n', outfile);
  129.     }
  130.   fflush (outfile);
  131. }
  132.  
  133.  
  134. DUMB_reset()
  135. {
  136.   free (dumb_matrix);
  137.   dumb_matrix = NULL;
  138. }
  139.  
  140.  
  141. DUMB_linetype(linetype)
  142. int linetype;
  143. {
  144.   static char pen_type[7] = {'*', '#', '$', '%', '@', '&', '='};
  145.  
  146.   if (linetype == -2)
  147.     dumb_pen = DUMB_BORDER_CONST;
  148.   else if (linetype == -1)
  149.     dumb_pen = DUMB_AXIS_CONST;
  150.   else
  151.     {
  152.       linetype = linetype % 7;
  153.       dumb_pen = pen_type[linetype];
  154.     }
  155. }
  156.  
  157.  
  158. DUMB_move(x, y)
  159. int x, y;
  160. {
  161.   dumb_x = x;
  162.   dumb_y = y;
  163. }
  164.  
  165.  
  166. DUMB_point(x,y,point)
  167. int x,y,point;
  168. {
  169.   dumb_set_pixel (x, y, point == -1 ? '.' : point % 26 + 'A', 4);
  170. }
  171.  
  172.  
  173. DUMB_vector(x,y)
  174. int x,y;
  175. {
  176.   char pen, pen1;
  177.   int priority;
  178.   int delta;
  179.  
  180.   if (abs (y - dumb_y) > abs (x - dumb_x))
  181.     {
  182.       switch (dumb_pen)
  183.        {
  184.        case DUMB_AXIS_CONST:
  185.          pen = ':';
  186.          pen1 = '+';
  187.          priority = 1;
  188.          break;
  189.  
  190.        case DUMB_BORDER_CONST:
  191.          pen = '|';
  192.          pen1 = '+';
  193.          priority = 2;
  194.          break;
  195.  
  196.        default:
  197.          pen = dumb_pen;
  198.          pen1 = dumb_pen;
  199.          priority = 3;
  200.          break;
  201.        }
  202.       dumb_set_pixel (dumb_x, dumb_y, pen1, priority);
  203.       for (delta = 1; delta < abs (y - dumb_y); delta++)
  204.        dumb_set_pixel (dumb_x
  205.                        + (int) ((double) (x - dumb_x) * delta / abs(y - dumb_y)
  206.                                 + 0.5),
  207.                        dumb_y + delta * sign (y - dumb_y),
  208.                        pen, priority);
  209.       dumb_set_pixel (x, y, pen1, priority);
  210.     }
  211.   else if (abs (x - dumb_x) > abs (y - dumb_y))
  212.     {
  213.       switch (dumb_pen)
  214.        {
  215.        case DUMB_AXIS_CONST:
  216.          pen = '.';
  217.          pen1 = '+';
  218.          priority = 1;
  219.          break;
  220.  
  221.        case DUMB_BORDER_CONST:
  222.          pen = '-';
  223.          pen1 = '+';
  224.          priority = 2;
  225.          break;
  226.  
  227.        default:
  228.          pen = dumb_pen;
  229.          pen1 = dumb_pen;
  230.          priority = 3;
  231.          break;
  232.        }
  233.       dumb_set_pixel (dumb_x, dumb_y, pen1, priority);
  234.       for (delta = 1; delta < abs (x - dumb_x); delta++)
  235.        dumb_set_pixel (dumb_x + delta * sign (x - dumb_x),
  236.                        dumb_y +
  237.                        (int) ((double) (y - dumb_y) * delta / abs(x - dumb_x)
  238.                               + 0.5),
  239.                        pen, priority);
  240.       dumb_set_pixel (x, y, pen1, priority);
  241.     }
  242.   else
  243.     {
  244.       switch (dumb_pen)
  245.        {
  246.        case DUMB_AXIS_CONST:    /* zero length axis */
  247.          pen = '+';
  248.          priority = 1;
  249.          break;
  250.  
  251.        case DUMB_BORDER_CONST:    /* zero length border */
  252.          pen = '+';
  253.          priority = 2;
  254.          break;
  255.  
  256.        default:
  257.          pen = dumb_pen;
  258.          priority = 3;
  259.          break;
  260.        }
  261.       for (delta = 0; delta <= abs (x - dumb_x); delta++)
  262.     dumb_set_pixel (dumb_x + delta * sign (x - dumb_x),
  263.             dumb_y + delta * sign (y - dumb_y),
  264.             pen, priority);
  265.     }
  266.   dumb_x = x;
  267.   dumb_y = y;
  268. }
  269.  
  270.  
  271. DUMB_put_text(x,y,str)
  272. int x, y;
  273. char *str;
  274. {
  275.   int length;
  276.   int delta;
  277.  
  278.   length = strlen(str);
  279.   if (x + length > dumb_xmax)
  280.     x = max (0, dumb_xmax - length);
  281.  
  282.   for (; x < dumb_xmax && *str; x++, str++)
  283.     dumb_set_pixel (x, y, *str, 5);
  284. }
  285.  
  286.  
  287. DUMB_arrow (sx,sy,ex,ey)
  288. int sx,sy,ex,ey;
  289. {
  290.   char saved_pen;
  291.   char saved_x;
  292.   char saved_y;
  293.  
  294.   saved_pen = dumb_pen;
  295.   saved_x = dumb_x;
  296.   saved_y = dumb_y;
  297.  
  298.   dumb_pen = '>';
  299.   dumb_x = sx;
  300.   dumb_y = sy;
  301.   DUMB_vector (ex,ey);
  302.  
  303.   dumb_pen = saved_pen;
  304.   dumb_x = saved_x;
  305.   dumb_y = saved_y;
  306. }
  307.